package com.linyaonan.zuochengyun._01._03;

/**
 * 传统二分问题
 * @author: Lin
 * @date: 2022/7/24
 */
public class CommonDichotomize {

    public static void main(String[] args) {
        int[] org = {1,2,3,4,5,6,7,8,9};

        boolean b = find(org, 10);
        System.out.println(b);
    }

    public static boolean find(int[] org, int num) {
        if (org == null || org.length == 0) {
            return false;
        }

        int l = 0;
        int r = org.length - 1;

        while (l <= r) {
            int mid = l + (r - l) >> 1;
            if (org[mid] == num) {
                return true;
            } else {
                if (org[mid] < num) {
                    l = mid + 1;
                } else {
                    r = mid -1;
                }
            }
        }
        return false;


    }

}
